From a8849f0aff07be8165d7a05e0eeefc2db212bc3f Mon Sep 17 00:00:00 2001 From: "kaf24@firebug.cl.cam.ac.uk" Date: Sun, 6 Nov 2005 16:40:33 +0100 Subject: [PATCH] Add support for the ioport_permission dom0 op to xend and xm xm now accepts a parameter 'ioports' that accepts a hex ioport or ioport range, in the form 02f8[-02ff] Signed-off-by: Jody Belka --- tools/python/xen/xend/XendDomain.py | 34 +++++++++++++++++++++++++ tools/python/xen/xend/XendDomainInfo.py | 3 ++- tools/python/xen/xm/create.py | 29 +++++++++++++++++++++ 3 files changed, 65 insertions(+), 1 deletion(-) diff --git a/tools/python/xen/xend/XendDomain.py b/tools/python/xen/xend/XendDomain.py index 3c0532645c..a429852788 100644 --- a/tools/python/xen/xend/XendDomain.py +++ b/tools/python/xen/xend/XendDomain.py @@ -492,6 +492,40 @@ class XendDomain: except Exception, ex: raise XendError(str(ex)) + def domain_ioport_range_enable(self, domid, first, last): + """Enable access to a range of IO ports for a domain + + @param first: first IO port + @param last: last IO port + @return: 0 on success, -1 on error + """ + dominfo = self.domain_lookup(domid) + nr_ports = last - first + 1 + try: + return xc.domain_ioport_permission(dominfo.getDomid(), + first_port = first, + nr_ports = nr_ports, + allow_access = 1) + except Exception, ex: + raise XendError(str(ex)) + + def domain_ioport_range_disable(self, domid, first, last): + """Disable access to a range of IO ports for a domain + + @param first: first IO port + @param last: last IO port + @return: 0 on success, -1 on error + """ + dominfo = self.domain_lookup(domid) + nr_ports = last - first + 1 + try: + return xc.domain_ioport_permission(dominfo.getDomid(), + first_port = first, + nr_ports = nr_ports, + allow_access = 0) + except Exception, ex: + raise XendError(str(ex)) + def instance(): """Singleton constructor. Use this instead of the class constructor. diff --git a/tools/python/xen/xend/XendDomainInfo.py b/tools/python/xen/xend/XendDomainInfo.py index 7e2199ec6e..f8ccc0d14e 100644 --- a/tools/python/xen/xend/XendDomainInfo.py +++ b/tools/python/xen/xend/XendDomainInfo.py @@ -1400,9 +1400,10 @@ def addControllerClass(device_class, cls): controllerClasses[device_class] = cls -from xen.xend.server import blkif, netif, tpmif, pciif, usbif +from xen.xend.server import blkif, netif, tpmif, pciif, iopif, usbif addControllerClass('vbd', blkif.BlkifController) addControllerClass('vif', netif.NetifController) addControllerClass('vtpm', tpmif.TPMifController) addControllerClass('pci', pciif.PciController) +addControllerClass('ioports', iopif.IOPortsController) addControllerClass('usb', usbif.UsbifController) diff --git a/tools/python/xen/xm/create.py b/tools/python/xen/xm/create.py index d844b2044c..c73d66c2f9 100644 --- a/tools/python/xen/xm/create.py +++ b/tools/python/xen/xm/create.py @@ -241,6 +241,12 @@ gopts.var('pci', val='BUS,DEV,FUNC', For example '-pci c0,02,1a'. The option may be repeated to add more than one pci device.""") +gopts.var('ioports', val='FROM[-TO]', + fn=append_value, default=[], + use="""Add a legacy I/O range to a domain, using given params (in hex). + For example '-ioports 02f8-02ff'. + The option may be repeated to add more than one i/o range.""") + gopts.var('usb', val='PATH', fn=append_value, default=[], use="""Add a physical USB port to a domain, as specified by the path @@ -439,6 +445,13 @@ def configure_pci(config_devs, vals): config_pci = ['pci', ['bus', bus], ['dev', dev], ['func', func]] config_devs.append(['device', config_pci]) +def configure_ioports(config_devs, vals): + """Create the config for legacy i/o ranges. + """ + for (io_from, io_to) in vals.ioports: + config_ioports = ['ioports', ['from', io_from], ['to', io_to]] + config_devs.append(['device', config_ioports]) + def configure_usb(config_devs, vals): for path in vals.usb: config_usb = ['usb', ['path', path]] @@ -611,6 +624,7 @@ def make_config(vals): config_devs = [] configure_disks(config_devs, vals) configure_pci(config_devs, vals) + configure_ioports(config_devs, vals) configure_vifs(config_devs, vals) configure_usb(config_devs, vals) configure_vtpm(config_devs, vals) @@ -645,6 +659,20 @@ def preprocess_pci(vals): pci.append(hexd) vals.pci = pci +def preprocess_ioports(vals): + if not vals.ioports: return + ioports = [] + for v in vals.ioports: + d = v.split('-') + if len(d) < 1 || len(d) > 2: + err('Invalid i/o port range specifier: ' + v) + if len(d) == 1: + d.append(d[0]) + # Components are in hex: add hex specifier. + hexd = map(lambda v: '0x'+v, d) + ioports.append(hexd) + vals.ioports = ioports + def preprocess_vifs(vals): if not vals.vif: return vifs = [] @@ -777,6 +805,7 @@ def preprocess(vals): err("No kernel specified") preprocess_disk(vals) preprocess_pci(vals) + preprocess_ioports(vals) preprocess_vifs(vals) preprocess_ip(vals) preprocess_nfs(vals) -- 2.30.2